/*******************************************************************************
File    : NSS_77_Merging.do
Project : Bank Expansion and Moneylender Interest Rates - RDD Evidence from India
Purpose : Clean NSS 77 district names and fuzzy-match to RBI 2005 MOF dataset
Author  : Kannan Narayanaswamy
Updated : 09 Feb 2026
*******************************************************************************/

clear all
set more off

*------------------------------------------------------------------------------
* 1. Load NSS 70 mapping file and map 2013 districts to 2001 parent districts
*------------------------------------------------------------------------------
use "Data\NSS_77_District_Codes.dta", clear

* Convert district codes to numeric for matching
destring NSS_77_Code, replace

gen Parent_District = District

* DISTRICT NAME DIFFERENCES (or renamings done bw 2001-19) Changes	 *

if 1 {
* Andaman & Nicobar Islands
replace Parent_District = "Nicobar" if State_UT=="Andaman & Nicobar Islands" & District=="Nicobars"

* Andhra Pradesh
replace Parent_District = "Nellore" if State_UT=="Andhra Pradesh" & District=="Sri Potti Sriramulu Nellore"
replace Parent_District = "Cuddapah" if State_UT=="Andhra Pradesh" & District=="Y.S.R. (Cuddapah)"
replace Parent_District = "Vishakhapatnam" if State_UT=="Andhra Pradesh" & District=="Visakhapatnam"

* Arunachal Pradesh
replace Parent_District = "Chunglang" if State_UT=="Arunachal Pradesh" & District=="Changlang"
replace Parent_District = "Papumpare" if State_UT=="Arunachal Pradesh" & District=="Papum Pare"

* Assam
replace Parent_District = "North Cachar Hills" if State_UT=="Assam" & District=="Dima Hasao"
replace Parent_District = "Kakrojhar" if State_UT=="Assam" & District=="Kokrajhar"
replace Parent_District = "Sibsagar" if State_UT=="Assam" & District=="Sivasagar"

* Bihar
replace Parent_District = "Kaimur" if State_UT=="Bihar" & District=="Kaimur (Bhabua)"
replace Parent_District = "Paschimi Champaran" if State_UT=="Bihar" & District=="Pashchim Champaran"
replace Parent_District = "Purbi Champaran" if State_UT=="Bihar" & District=="Purba Champaran"

* Chhattisgarh
replace Parent_District = "Dantewada" if State_UT=="Chhattisgarh" & District=="Dakshin Bastar Dantewada"
replace Parent_District = "Kawardha" if State_UT=="Chhattisgarh" & District=="Kabeerdham"
replace Parent_District = "Kanker" if State_UT=="Chhattisgarh" & District=="Uttar Bastar Kanker"

* Delhi
replace Parent_District = "N.C.T. Delhi" if State_UT=="Delhi" & inlist(District,"Central","East","New Delhi","North","North East","North West","South","South West","West")

* Gujarat
replace Parent_District = "Ahmedabad" if State_UT=="Gujarat" & District=="Ahmadabad"
replace Parent_District = "amnagar" if State_UT=="Gujarat" & District=="Jamnagar"
replace Parent_District = "Panch Mahal" if State_UT=="Gujarat" & District=="Panch Mahals"
replace Parent_District = "Dangs" if State_UT=="Gujarat" & District=="The Dangs"

* Himachal Pradesh
replace Parent_District = "Kulu" if State_UT=="Himachal Pradesh" & District=="Kullu"
replace Parent_District = "Simla" if State_UT=="Himachal Pradesh" & District=="Shimla"

* Jammu & Kashmir
replace Parent_District = "Baramulla" if State_UT=="Jammu & Kashmir" & District=="Baramula"
replace Parent_District = "Ladakh" if State_UT=="Jammu & Kashmir" & District=="Leh"
replace Parent_District = "Poonch" if State_UT=="Jammu & Kashmir" & District=="Punch"

* Jharkhand
replace Parent_District = "Hazaribag" if State_UT=="Jharkhand" & District=="Hazaribagh"
replace Parent_District = "Koderma" if State_UT=="Jharkhand" & District=="Kodarma"
replace Parent_District = "Lohardagga" if State_UT=="Jharkhand" & District=="Lohardaga"
replace Parent_District = "Paschimi Singhbhum" if State_UT=="Jharkhand" & District=="Pashchimi Singhbhum"
replace Parent_District = "Sahebganj" if State_UT=="Jharkhand" & District=="Sahibganj"

* Karnataka
replace Parent_District = "Bagalkote" if State_UT=="Karnataka" & District=="Bagalkot"
replace Parent_District = "Dakshin Kannad" if State_UT=="Karnataka" & District=="Dakshina Kannada"
replace Parent_District = "Davangere" if State_UT=="Karnataka" & District=="Davanagere"
replace Parent_District = "Uttar Kannad" if State_UT=="Karnataka" & District=="Uttara Kannada"

* Kerala
replace Parent_District = "Alapuzha" if State_UT=="Kerala" & District=="Alappuzha"

* Madhya Pradesh
replace Parent_District = "East Nimar" if State_UT=="Madhya Pradesh" & District=="Khandwa (East Nimar)"
replace Parent_District = "West Nimar" if State_UT=="Madhya Pradesh" & District=="Khargone (West Nimar)"

* Maharashtra
replace Parent_District = "Ahmednagar" if State_UT=="Maharashtra" & District=="Ahmadnagar"
replace Parent_District = "Buldhana" if State_UT=="Maharashtra" & District=="Buldana"
replace Parent_District = "Gondia" if State_UT=="Maharashtra" & District=="Gondiya"
replace Parent_District = "Greater Mumbai" if State_UT=="Maharashtra" & District=="Mumbai"
replace Parent_District = "Nasik" if State_UT=="Maharashtra" & District=="Nashik"
replace Parent_District = "Raigad" if State_UT=="Maharashtra" & District=="Raigarh"

* Manipur
replace Parent_District = "Bishenpur" if State_UT=="Manipur" & District=="Bishnupur"

* Meghalaya
replace Parent_District = "Bhoi" if State_UT=="Meghalaya" & District=="Ribhoi"

* Mizoram
replace Parent_District = "Aizawl" if State_UT=="Mizoram" & District=="Aizwal"

* Odisha
replace Parent_District = "Angul" if State_UT=="Odisha" & District=="Anugul"
replace Parent_District = "Bolangir" if State_UT=="Odisha" & District=="Balangir"
replace Parent_District = "Boudh" if State_UT=="Odisha" & District=="Baudh"
replace Parent_District = "Deogarh" if State_UT=="Odisha" & District=="Debagarh"
replace Parent_District = "Jagatsinghpur" if State_UT=="Odisha" & District=="Jagatsinghapur"
replace Parent_District = "Jajpur" if State_UT=="Odisha" & District=="Jajapur"
replace Parent_District = "Keonjhar" if State_UT=="Odisha" & District=="Kendujhar"
replace Parent_District = "Nawrangpur" if State_UT=="Odisha" & District=="Nabarangapur"
replace Parent_District = "Sonepur" if State_UT=="Odisha" & District=="Subarnapur"

* Puducherry
replace Parent_District = "Pondicherry" if State_UT=="Puducherry" & District=="Puducherry"

* Punjab
replace Parent_District = "Bathinda" if State_UT=="Punjab" & District=="Bhatinda"
replace Parent_District = "Ferozpur" if State_UT=="Punjab" & District=="Firozpur"
replace Parent_District = "Nawanshahr" if State_UT=="Punjab" & District=="Shahid Bhagat Singh Nagar"

* Rajasthan
replace Parent_District = "Dholpur" if State_UT=="Rajasthan" & District=="Dhaulpur"
replace Parent_District = "Jhunjhunu" if State_UT=="Rajasthan" & District=="Jhunjhunun"
replace Parent_District = "Madhopur" if State_UT=="Rajasthan" & District=="Sawai Madhopur"
replace Parent_District = "Ganganagar" if State_UT=="Rajasthan" & District=="Sri Ganganagar"

* Sikkim
replace Parent_District = "East Sikkim" if State_UT=="Sikkim" & District=="East District"
replace Parent_District = "North Sikkim" if State_UT=="Sikkim" & District=="North District"
replace Parent_District = "South Sikkim" if State_UT=="Sikkim" & District=="South District"
replace Parent_District = "West Sikkim" if State_UT=="Sikkim" & District=="West District"

* Tamil Nadu
replace Parent_District = "Kanyakumari" if State_UT=="Tamil Nadu" & District=="Kanniyakumari"
replace Parent_District = "Nilgiris" if State_UT=="Tamil Nadu" & District=="The Nilgiris"
replace Parent_District = "Toothukudi" if State_UT=="Tamil Nadu" & District=="Thoothukkudi"
replace Parent_District = "Tiruchirapalli" if State_UT=="Tamil Nadu" & District=="Tiruchirappalli"
replace Parent_District = "Villupuram" if State_UT=="Tamil Nadu" & District=="Viluppuram"

* Uttar Pradesh
replace Parent_District = "Kanauj" if State_UT=="Uttar Pradesh" & District=="Kannauj"
replace Parent_District = "Kushi Nagar" if State_UT=="Uttar Pradesh" & District=="Kushinagar"
replace Parent_District = "Hathras" if State_UT=="Uttar Pradesh" & District=="Mahamaya Nagar"
replace Parent_District = "Rai Bareli" if State_UT=="Uttar Pradesh" & District=="Rae Bareli"
replace Parent_District = "Sant Ravidas Nagar" if State_UT=="Uttar Pradesh" & District=="Sant Ravidas Nagar(Bhadohi)"
replace Parent_District = "Shravasti" if State_UT=="Uttar Pradesh" & District=="Shrawasti"
replace Parent_District = "Siddharthanagar" if State_UT=="Uttar Pradesh" & District=="Siddharthnagar"

* Uttaranchal
replace Parent_District = "Dehra Dun" if State_UT=="Uttarakhand" & District=="Dehradun"
replace Parent_District = "Haridwar" if State_UT=="Uttarakhand" & District=="Hardwar"
replace Parent_District = "Uttar Kashi" if State_UT=="Uttarakhand" & District=="Uttarkashi"

* West Bengal
replace Parent_District = "Cooch Bihar" if State_UT=="West Bengal" & District=="Koch Bihar"
replace Parent_District = "North 24 Parganas" if State_UT=="West Bengal" & District=="North Twenty Four Parganas"
replace Parent_District = "South 24 Parganas" if State_UT=="West Bengal" & District=="South Twenty Four Parganas"
}

* PARENT DISTRICT MAPPINGS (or renamings done bw 2001-19) Changes	 *

if 1 {
* Andaman & Nicobar Islands
replace Parent_District = "Andaman" if State_UT=="Andaman & Nicobar Islands" & District=="North & Middle Andaman"
replace Parent_District = "Andaman" if State_UT=="Andaman & Nicobar Islands" & District=="South Andaman"

* Telangana (incl. Telangana carve-outs)
replace Parent_District = "Khammam" if State_UT=="Telangana" & District=="Bhadradri"
replace Parent_District = "Karimnagar" if State_UT=="Telangana" & District=="Jagtial"
replace Parent_District = "Warangal" if State_UT=="Telangana" & District=="Jangaon"
replace Parent_District = "Warangal" if State_UT=="Telangana" & District=="Jayashankar"
replace Parent_District = "Mahbubnagar" if State_UT=="Telangana" & District=="Jogulamba"
replace Parent_District = "Nizamabad" if State_UT=="Telangana" & District=="Kamareddy"
replace Parent_District = "Adilabad" if State_UT=="Telangana" & District=="Komaram Bheem"
replace Parent_District = "Warangal" if State_UT=="Telangana" & District=="Mahabubabad"
replace Parent_District = "Adilabad" if State_UT=="Telangana" & District=="Mancherial"
replace Parent_District = "Rangareddy" if State_UT=="Telangana" & District=="Medchal-Malkajgiri"
replace Parent_District = "Mahbubnagar" if State_UT=="Telangana" & District=="Nagarkurnool"
replace Parent_District = "Adilabad" if State_UT=="Telangana" & District=="Nirmal"
replace Parent_District = "Karimnagar" if State_UT=="Telangana" & District=="Peddapalli"
replace Parent_District = "Karimnagar" if State_UT=="Telangana" & District=="Rajanna"
replace Parent_District = "Medak" if State_UT=="Telangana" & District=="Sangareddy"
replace Parent_District = "Medak" if State_UT=="Telangana" & District=="Siddipet"
replace Parent_District = "Nalgonda" if State_UT=="Telangana" & District=="Suryapet"
replace Parent_District = "Multiple" if State_UT=="Telangana" & District=="Vikarabad"
replace Parent_District = "Mahbubnagar" if State_UT=="Telangana" & District=="Wanaparthy"
replace Parent_District = "Warangal" if State_UT=="Telangana" & District=="Warangal Rural"
replace Parent_District = "Warangal" if State_UT=="Telangana" & District=="Warangal Urban"
replace Parent_District = "Nalgonda" if State_UT=="Telangana" & District=="Yadadri"

* Arunachal Pradesh
replace Parent_District = "Lohit" if State_UT=="Arunachal Pradesh" & District=="Anjaw"
replace Parent_District = "Lower Subansiri" if State_UT=="Arunachal Pradesh" & District=="Kurung Kumey"
replace Parent_District = "Dibang Valley" if State_UT=="Arunachal Pradesh" & District=="Lower Dibang Valley"

* Assam
replace Parent_District = "Multiple" if State_UT=="Assam" & District=="Baksa"
replace Parent_District = "Multiple" if State_UT=="Assam" & District=="Chirang"
replace Parent_District = "Kamrup" if State_UT=="Assam" & District=="Kamrup Metropolitan"
replace Parent_District = "Darrang" if State_UT=="Assam" & District=="Udalguri"

* Bihar
replace Parent_District = "Jehanabad" if State_UT=="Bihar" & District=="Arwal"

* Chhattisgarh
replace Parent_District = "Durg" if State_UT=="Chhattisgarh" & District=="Balod"
replace Parent_District = "Raipur" if State_UT=="Chhattisgarh" & District=="Balodabazar"
replace Parent_District = "Surguja" if State_UT=="Chhattisgarh" & District=="Balrampur"
replace Parent_District = "Durg" if State_UT=="Chhattisgarh" & District=="Bemetara"
replace Parent_District = "Dantewada" if State_UT=="Chhattisgarh" & District=="Bijapur"
replace Parent_District = "Raipur" if State_UT=="Chhattisgarh" & District=="Gariyaband"
replace Parent_District = "Bastar" if State_UT=="Chhattisgarh" & District=="Kondagaon"
replace Parent_District = "Bilaspur" if State_UT=="Chhattisgarh" & District=="Mungeli"
replace Parent_District = "Bastar" if State_UT=="Chhattisgarh" & District=="Narayanpur"
replace Parent_District = "Dantewada" if State_UT=="Chhattisgarh" & District=="Sukama"
replace Parent_District = "Surguja" if State_UT=="Chhattisgarh" & District=="Surajpur"

* Gujarat
replace Parent_District = "Sabar Kantha" if State_UT=="Gujarat" & District=="Arvalli"
replace Parent_District = "Multiple" if State_UT=="Gujarat" & District=="Botad"
replace Parent_District = "Vadodara" if State_UT=="Gujarat" & District=="Chhota Udepur"
replace Parent_District = "amnagar" if State_UT=="Gujarat" & District=="Dev Bhumi-Dwarka"
replace Parent_District = "Junagadh" if State_UT=="Gujarat" & District=="Gir Somnath"
replace Parent_District = "Multiple" if State_UT=="Gujarat" & District=="Mahisagar"
replace Parent_District = "Multiple" if State_UT=="Gujarat" & District=="Morbi"
replace Parent_District = "Surat" if State_UT=="Gujarat" & District=="Tapi"

* Haryana
replace Parent_District = "Faridabad" if State_UT=="Haryana" & District=="Mewat"
replace Parent_District = "Faridabad" if State_UT=="Haryana" & District=="Palwal"

* Jammu & Kashmir
replace Parent_District = "Baramulla" if State_UT=="Jammu & Kashmir" & District=="Bandipore"
replace Parent_District = "Srinagar" if State_UT=="Jammu & Kashmir" & District=="Ganderbal"
replace Parent_District = "Doda" if State_UT=="Jammu & Kashmir" & District=="Kishtwar"
replace Parent_District = "Anantnag" if State_UT=="Jammu & Kashmir" & District=="Kulgam"
replace Parent_District = "Doda" if State_UT=="Jammu & Kashmir" & District=="Ramban"
replace Parent_District = "Udhampur" if State_UT=="Jammu & Kashmir" & District=="Reasi"
replace Parent_District = "Multiple" if State_UT=="Jammu & Kashmir" & District=="Samba"
replace Parent_District = "Pulwama" if State_UT=="Jammu & Kashmir" & District=="Shupiyan"

* Jharkhand
replace Parent_District = "Dumka" if State_UT=="Jharkhand" & District=="Jamtara"
replace Parent_District = "Ranchi" if State_UT=="Jharkhand" & District=="Khunti"
replace Parent_District = "Palamu" if State_UT=="Jharkhand" & District=="Latehar"
replace Parent_District = "Hazaribag" if State_UT=="Jharkhand" & District=="Ramgarh"
replace Parent_District = "Purbi Singhbhum" if State_UT=="Jharkhand" & District=="Saraikela-Kharsawan"
replace Parent_District = "Gumla" if State_UT=="Jharkhand" & District=="Simdega"

* Karnataka
replace Parent_District = "Bangalore Urban" if State_UT=="Karnataka" & District=="Bangalore"
replace Parent_District = "Kolar" if State_UT=="Karnataka" & District=="Chikkaballapura"
replace Parent_District = "Bangalore Rural" if State_UT=="Karnataka" & District=="Ramanagara"
replace Parent_District = "Gulbarga" if State_UT=="Karnataka" & District=="Yadgir"

* Madhya Pradesh
replace Parent_District = "Jhabua" if State_UT=="Madhya Pradesh" & District=="Alirajpur"
replace Parent_District = "Shahdol" if State_UT=="Madhya Pradesh" & District=="Anuppur"
replace Parent_District = "Guna" if State_UT=="Madhya Pradesh" & District=="Ashoknagar"
replace Parent_District = "East Nimar" if State_UT=="Madhya Pradesh" & District=="Burhanpur"
replace Parent_District = "Sidhi" if State_UT=="Madhya Pradesh" & District=="Singrauli"

* Maharashtra
replace Parent_District = "Greater Mumbai" if State_UT=="Maharashtra" & District=="Mumbai Suburban"

* Nagaland
replace Parent_District = "Tuensang" if State_UT=="Nagaland" & District=="Kiphire"
replace Parent_District = "Tuensang" if State_UT=="Nagaland" & District=="Longleng"
replace Parent_District = "Kohima" if State_UT=="Nagaland" & District=="Peren"

* Punjab
replace Parent_District = "Sangrur" if State_UT=="Punjab" & District=="Barnala"
replace Parent_District = "Ferozpur" if State_UT=="Punjab" & District=="Fazilka"
replace Parent_District = "Gurdaspur" if State_UT=="Punjab" & District=="Pathankot"
replace Parent_District = "Multiple" if State_UT=="Punjab" & District=="Sahibzada Ajit Singh Nagar"
replace Parent_District = "Amritsar" if State_UT=="Punjab" & District=="Tarn Taran"

* Rajasthan
replace Parent_District = "Multiple" if State_UT=="Rajasthan" & District=="Pratapgarh"

* Tamil Nadu
replace Parent_District = "Perambalur" if State_UT=="Tamil Nadu" & District=="Ariyalur"
replace Parent_District = "Dharmapuri" if State_UT=="Tamil Nadu" & District=="Krishnagiri"
replace Parent_District = "Multiple" if State_UT=="Tamil Nadu" & District=="Tiruppur"

* Uttar Pradesh
replace Parent_District = "Etah" if State_UT=="Uttar Pradesh" & District=="Kanshiram Nagar"

* West Bengal
replace Parent_District = "Jalpaiguri" if State_UT=="West Bengal" & District=="Alipurduar"
replace Parent_District = "Medinpur_old" if State_UT=="West Bengal" & District=="Jhargram"
replace Parent_District = "Darjiling" if State_UT=="West Bengal" & District=="Kalimpong"
replace Parent_District = "Barddhaman" if State_UT=="West Bengal" & District=="Paschim Barddhaman"
replace Parent_District = "Medinpur_old" if State_UT=="West Bengal" & District=="Paschim Medinipur"
replace Parent_District = "Barddhaman" if State_UT=="West Bengal" & District=="Purba Barddhaman"
replace Parent_District = "Medinpur_old" if State_UT=="West Bengal" & District=="Purba Medinipur"

}

rename District Child_District
rename Parent_District District

* Standardize State names to match MOF conventions
replace State_UT = "Pondicherry"   if State_UT == "Puducherry"
replace State_UT = "Uttaranchal"   if State_UT == "Uttarakhand"
replace State_UT = "Orissa"        if State_UT == "Odisha"
replace State_UT = "Andhra Pradesh" if State_UT == "Telangana"

* Save cleaned NSS mapping
tempfile nss_77_map
save `nss_77_map'

*------------------------------------------------------------------------------
* 3. Fuzzy match to RBI–Census (2005) dataset
*------------------------------------------------------------------------------


reclink State_UT District using "Data\MOF_Data\RBI_2005_Q1\MOF_Census_2005_Q1.dta", ///
    idmaster(NSS_77_Code) idusing(ID_RBI) gen(match_score)

gen str4 NSS_Code = string(NSS_77_Code, "%04.0f")
drop NSS_77_Code UState_UT UDistrict State_Code District_Code  match_score
rename NSS_Code NSS_77_Codes
	
	
*------------------------------------------------------------------------------
* 4. Check - Are all the 583 districts mapped?
*------------------------------------------------------------------------------

preserve

count

duplicates drop ID_RBI, force

drop _merge

merge 1:1 ID_RBI using "Data\MOF_Data\RBI_2005_Q1\MOF_Census_2005_Q1.dta"

tab District if _merge !=3

restore


count
* There are 583 districts. Therefore, all districts are mapped.
* Chirag, Tiruppur, Baksa, Pratapgarh, Samba, Botad, Mahisagar, Vikrabad, Morbi and Sahibzada Ajit Singh Nagar (or Mohali) are the 9 districts in 2019 that have multiple parents. So, we are the observations related to them it from the analysis.

drop if _merge != 3
drop _merge

rename Underbanked treatment

save "Data\MOF_Census_NSS_77", replace